home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
egebook.lha
/
ege.book
/
5
/
String.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-05
|
1KB
|
55 lines
#ifndef _String
#define _String
#include <iostream.h>
#include <string.h>
#include "bool.h"
class String {
char *str ;
static const int MaxLength;
public:
String(const char *s = "") {
str = new char[strlen(s) + 1];
strcpy(str,s);
}
String(const String &s) {
str = new char[strlen(s.str) + 1];
strcpy(str,s.str);
}
String& operator=(const String& s) {
if (&s != this) {
delete [] str;
str = new char[strlen(s.str) + 1];
strcpy(str,s.str);
}
return *this;
}
String& operator+(const String& s) {
char *tmp = new char [strlen(str) + strlen(s.str) +1];
strcpy(tmp,str);
strcat(tmp,s.str);
return *new String(tmp);
}
void print() {
cout << str;
}
int operator==(const String& s) {
return !strcmp(str,s.str);
}
bool contains(String);
// operator char*() {
// return str;
// }
friend istream& operator>>(istream&, String&);
friend ostream& operator<<(ostream&, String&);
~String(){
delete [] str;
}
} ;
#endif